package company.permute;

import java.util.*;
import java.util.regex.Pattern;

/**
 * 排列，数字可以重复使用
 *
 */
public class CrimeTime {
    static List<String> res = new ArrayList<>();
    static TreeSet<String> allList = new TreeSet<>();

    public static void main(String[] args) {
        // 输入
        Scanner scanner = new Scanner(System.in);
        String orginalTime = scanner.nextLine();
        String splitStr = orginalTime.replace(":", "");
        List<String> inputList = new ArrayList<>();
        for (int i = 0; i < splitStr.length(); i++) {
            char c = splitStr.charAt(i);
            inputList.add(String.valueOf(c));
        }
        permuteUnique(inputList);

        List<String> lst = new ArrayList<>(allList);
        // 找出原始时间的下标+1
        int i = lst.lastIndexOf(orginalTime);
        Collections.sort(lst);
        // 如果原始时间是最后一个，说明犯罪时间落在第二天如 23：59->22:22
        if (i == lst.size() - 1) {
            // 取最小数字，组合成犯罪时间
            System.out.println(lst.get(0));
        } else {
            System.out.println(lst.get(i + 1));
        }
    }

    public static TreeSet<String> permuteUnique(List<String> nums) {
        if (nums.size() == 0) {
            return allList;
        }
        dfs(nums, "");
        return allList;
    }

    public static void dfs(List<String> nums,  String s) {
        if (s.length() ==4) {
            String time = s.substring(0, 2) + ":" + s.substring(2, 4);
            if (TimePart.pattern.matcher(time).find()) {
                allList.add(time);
            }
            return;
        }

        for (int i = 0; i < nums.size(); i++) {
            s += nums.get(i);
            dfs(nums, s);
            s = s.substring(0,s.length()-1);
        }
    }

    private static class TimePart {
        private static final String regEx = "^([01]?[0-9]{1}|2[0-3]):[0-5][0-9]";
        private static final Pattern pattern = Pattern.compile(regEx);
    }
}
